import 'package:flutter/material.dart';

// Excise: Send data to new screen
// https://docs.flutter.dev/cookbook/navigation/returning-data
class Todo {
  final String title;
  final String description;

  Todo(this.title, this.description);
}

class TodoList extends StatelessWidget {
  const TodoList({super.key, required this.todos});
  final List<Todo> todos;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Todos'),
      ),
      body: ListView.builder(
        itemCount: todos.length,
        itemBuilder: (context, index) {
          var todo = todos[index];
          return ListTile(
            title: Text(todo.title),
            onTap: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => TodoItem(todo: todo),
                ),
              );
            },
          );
        },
      ),
    );
  }
}

class TodoItem extends StatelessWidget {
  const TodoItem({super.key, required this.todo});
  final Todo todo;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(todo.title),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: ListTile(
          title: Text(todo.title),
          subtitle: Text(todo.description),
        ),
      ),
    );
  }
}
